// DialogPathwayGenerator.cpp : implementation file
//

#include "stdafx.h"
#include "testSVG.h"
#include "DialogPathwayGenerator.h"
#include "DialogPathwayDisplay.h"
#include "testSVGDlg.h"
#include ".\dialogpathwaygenerator.h"

extern MOLECULE* MoleculesList;

// CDialogPathwayGenerator dialog

IMPLEMENT_DYNAMIC(CDialogPathwayGenerator, CDialog)
CDialogPathwayGenerator::CDialogPathwayGenerator(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogPathwayGenerator::IDD, pParent)
{
}

CDialogPathwayGenerator::~CDialogPathwayGenerator()
{
}

void CDialogPathwayGenerator::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDialogPathwayGenerator, CDialog)
	ON_BN_CLICKED(IDC_BUTTON_GENERATE_PATHWAY, OnBnClickedButtonGeneratePathway)
	ON_BN_CLICKED(IDC_BUTTON_CLEAR, OnBnClickedButtonClear)
	ON_BN_CLICKED(IDC_RADIO_LIGAND, OnBnClickedRadioLigand)
	ON_BN_CLICKED(IDC_RADIO_RECEPTOR, OnBnClickedRadioReceptor)
	ON_BN_CLICKED(IDC_RADIO_CHANNEL, OnBnClickedRadioChannel)
	ON_BN_CLICKED(IDC_RADIO_TF, OnBnClickedRadioTf)
	ON_BN_CLICKED(IDC_RADIO_KINASE, OnBnClickedRadioKinase)
	ON_BN_CLICKED(IDC_RADIO_PHOSPHATASE, OnBnClickedRadioPhosphatase)
	ON_BN_CLICKED(IDC_RADIO_VESICLE, OnBnClickedRadioVesicle)
	ON_BN_CLICKED(IDC_RADIO_CYTOSKELETON, OnBnClickedRadioCytoskeleton)
	ON_CBN_SELCHANGE(IDC_COMBO_CHANNEL, OnCbnSelchangeComboChannel)
END_MESSAGE_MAP()


// CDialogPathwayGenerator message handlers
int Source;
int Target;

void CDialogPathwayGenerator::OnOK()
{
	// TODO: Add your specialized code here and/or call the base class

	CDialog::OnOK();
}

void CDialogPathwayGenerator::OnBnClickedButtonGeneratePathway()
{
	// get the selections
	CString sourceNode;
	CString targetNode;

	CButton* checkTFs;
	CButton* checkVesicles;
	CButton* checkCytoskeletons;
	CButton* checkKinases;
	CButton* checkPhosphatases;
	CButton* checkChannels;
	CButton* checkReceptors;
	CButton* checkLigands;
	CComboBox* comboTFs = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	CComboBox* comboVesicles = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	CComboBox* comboCytoskeletons = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	CComboBox* comboKinases = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	CComboBox* comboPhosphatases = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	CComboBox* comboChannels = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);
	CComboBox* comboReceptors = (CComboBox*) GetDlgItem(IDC_COMBO_RECEPTOR);
	CComboBox* comboLigands = (CComboBox*) GetDlgItem(IDC_COMBO_LIGAND);

	checkTFs = (CButton*) GetDlgItem(IDC_RADIO_TF);
	checkKinases = (CButton*) GetDlgItem(IDC_RADIO_KINASE);
	checkPhosphatases = (CButton*) GetDlgItem(IDC_RADIO_PHOSPHATASE);
	checkVesicles = (CButton*) GetDlgItem(IDC_RADIO_VESICLE);
	checkCytoskeletons = (CButton*) GetDlgItem(IDC_RADIO_CYTOSKELETON);
	checkChannels = (CButton*) GetDlgItem(IDC_RADIO_CHANNEL);
	checkLigands = (CButton*) GetDlgItem(IDC_RADIO_LIGAND);
	checkReceptors = (CButton*) GetDlgItem(IDC_RADIO_RECEPTOR);
	
	if (checkLigands->GetCheck())
	{
		comboLigands->GetWindowText(sourceNode);
	}
	else if (checkReceptors->GetCheck())
	{
		comboReceptors->GetWindowText(sourceNode);
	}

	if (checkTFs->GetCheck())
	{
		comboTFs->GetWindowText(targetNode);
	}
	else if (checkKinases->GetCheck())
	{
		comboKinases->GetWindowText(targetNode);
	}
	else if (checkPhosphatases->GetCheck())
	{
		comboPhosphatases->GetWindowText(targetNode);
	}
	else if (checkVesicles->GetCheck())
	{
		comboVesicles->GetWindowText(targetNode);
	}
	else if (checkCytoskeletons->GetCheck())
	{
		comboCytoskeletons->GetWindowText(targetNode);
	}
	else if (checkChannels->GetCheck())
	{
		comboChannels->GetWindowText(targetNode);
	}

	m_sourceCondName1 = sourceNode;
	m_sourceCondName2 = "";
	m_sourceCondName3 = "";
	m_sourceCondName4 = "";
	m_targetCondName1 = targetNode;
	m_targetCondName2 = "";
	m_targetCondName3 = "";
	m_targetCondName4 = "";

	m_sourceCondType1 = "Name";
	m_sourceCondType2 = "Name";
	m_sourceCondType3 = "Name";
	m_sourceCondType4 = "Name";
	m_targetCondType1 = "Name";
	m_targetCondType2 = "Name";
	m_targetCondType3 = "Name";
	m_targetCondType4 = "Name";

	m_numberOfSteps = 8;
	m_maxSize = 50;
	
	CDialog::OnOK();
}

void CDialogPathwayGenerator::SetCheckForSource()
{
	CButton* checkLigands;
	CButton* checkReceptors;
	CButton* checkChannels;
	
	switch (Source)
	{
	case 1:
		checkLigands = (CButton*) GetDlgItem(IDC_RADIO_LIGAND);
		checkLigands->SetCheck(1);
		break;
	case 2:
		checkReceptors = (CButton*) GetDlgItem(IDC_RADIO_RECEPTOR);
		checkReceptors->SetCheck(1);
		break;
	case 3:
		checkChannels = (CButton*) GetDlgItem(IDC_RADIO_CHANNEL);
		checkChannels->SetCheck(1);
		break;
	}
}

void CDialogPathwayGenerator::SetCheckForTarget()
{
	CButton* checkTFs;
	CButton* checkVesicles;
	CButton* checkCytoskeletons;
	CButton* checkKinases;
	CButton* checkPhosphatases;

	switch (Target)
	{
	case 1:
		checkTFs = (CButton*) GetDlgItem(IDC_RADIO_TF);
		checkTFs->SetCheck(1);
		break;
	case 2:
		checkKinases = (CButton*) GetDlgItem(IDC_RADIO_KINASE);
		checkKinases->SetCheck(1);
		break;
	case 3:
		checkPhosphatases = (CButton*) GetDlgItem(IDC_RADIO_PHOSPHATASE);
		checkPhosphatases->SetCheck(1);
		break;
	case 4:
		checkVesicles = (CButton*) GetDlgItem(IDC_RADIO_VESICLE);
		checkVesicles->SetCheck(1);
		break;
	case 5:
		checkCytoskeletons = (CButton*) GetDlgItem(IDC_RADIO_CYTOSKELETON);
		checkCytoskeletons->SetCheck(1);
		break;
	}
}

BOOL CDialogPathwayGenerator::OnInitDialog()
{
	CDialog::OnInitDialog();

	MOLECULE* tempNode;

	CComboBox* ligandsCombo;
	CComboBox* tfsCombo;
	CComboBox* receptorsCombo;
	CComboBox* kinasesCombo;
	CComboBox* channelsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonCombo;

	ligandsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_LIGAND);
	receptorsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_RECEPTOR);
	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	tfsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	
	tempNode = MoleculesList;

	while (tempNode != NULL)
	{
		if (!strcmp(tempNode->moleculeType, "Ligand"))
		{
			ligandsCombo->InsertString(0,tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "Receptor"))
		{
			receptorsCombo->InsertString(0, tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "Channel"))
		{
			channelsCombo->InsertString(0, tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "Vesicle"))
		{
			vesiclesCombo->InsertString(0, tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "Kinase"))
		{
			kinasesCombo->InsertString(0, tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "Phosphatase"))
		{
			phosphatasesCombo->InsertString(0, tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "Cytoskeleton"))
		{
			cytoskeletonCombo->InsertString(0, tempNode->name);
		}
		if (!strcmp(tempNode->moleculeType, "TF"))
		{
			tfsCombo->InsertString(0, tempNode->name);
		}

		tempNode = tempNode->next;
	}

	tfsCombo->SetCurSel(0);
	cytoskeletonCombo->Clear();
	phosphatasesCombo->Clear();
	kinasesCombo->Clear();
	vesiclesCombo->Clear();
	channelsCombo->Clear();
	receptorsCombo->Clear();
	ligandsCombo->SetCurSel(0);

	Source = 1;
	Target = 1;
	
	SetCheckForSource();
	SetCheckForTarget();

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}


void CDialogPathwayGenerator::OnBnClickedButtonClear()
{
	// The pointer to my combo box.
	
	CComboBox* ligandsCombo;
	CComboBox* tfsCombo;
	
	ligandsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_LIGAND);
	tfsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	// Delete all of the text from the combo box's edit control.
	
	ligandsCombo->SetEditSel(0, -1);
	tfsCombo->Clear();

}

void CDialogPathwayGenerator::OnBnClickedRadioLigand()
{
	CComboBox* ligandsCombo;
	CComboBox* receptorsCombo;
	

	ligandsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_LIGAND);
	receptorsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_RECEPTOR);
	

	ligandsCombo->SetCurSel(0);
	
	receptorsCombo->Clear();
	receptorsCombo->SetWindowText("");
	ligandsCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioReceptor()
{
	CComboBox* ligandsCombo;
	CComboBox* receptorsCombo;

	ligandsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_LIGAND);
	receptorsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_RECEPTOR);

	ligandsCombo->Clear(); 
	ligandsCombo->SetWindowText("");
	receptorsCombo->SetCurSel(0);
	receptorsCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioChannel()
{
	CComboBox* kinasesCombo;
	CComboBox* TFsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonsCombo;
	CComboBox* channelsCombo;

	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	TFsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);

	kinasesCombo->Clear();
	kinasesCombo->SetWindowText("");
	phosphatasesCombo->Clear();
	phosphatasesCombo->SetWindowText("");
	vesiclesCombo->Clear();
	vesiclesCombo->SetWindowText("");
	cytoskeletonsCombo->Clear();
	cytoskeletonsCombo->SetWindowText("");
	TFsCombo->Clear();
	TFsCombo->SetWindowText("");

	channelsCombo->SetCurSel(0);
	channelsCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioTf()
{
	CComboBox* kinasesCombo;
	CComboBox* TFsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonsCombo;
	CComboBox* channelsCombo;

	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	TFsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);

	kinasesCombo->Clear();
	kinasesCombo->SetWindowText("");
	phosphatasesCombo->Clear();
	phosphatasesCombo->SetWindowText("");
	vesiclesCombo->Clear();
	vesiclesCombo->SetWindowText("");
	cytoskeletonsCombo->Clear();
	cytoskeletonsCombo->SetWindowText("");
	channelsCombo->Clear();
	channelsCombo->SetWindowText("");

	TFsCombo->SetCurSel(0);
	TFsCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioKinase()
{
	CComboBox* kinasesCombo;
	CComboBox* TFsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonsCombo;
	CComboBox* channelsCombo;


	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	TFsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);

	TFsCombo->Clear();
	TFsCombo->SetWindowText("");
	phosphatasesCombo->Clear();
	phosphatasesCombo->SetWindowText("");
	vesiclesCombo->Clear();
	vesiclesCombo->SetWindowText("");
	cytoskeletonsCombo->Clear();
	cytoskeletonsCombo->SetWindowText("");
	channelsCombo->Clear();
	channelsCombo->SetWindowText("");

	kinasesCombo->SetCurSel(0);
	kinasesCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioPhosphatase()
{
	CComboBox* kinasesCombo;
	CComboBox* TFsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonsCombo;
	CComboBox* channelsCombo;

	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	TFsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);

	TFsCombo->Clear();
	TFsCombo->SetWindowText("");
	kinasesCombo->Clear();
	kinasesCombo->SetWindowText("");
	vesiclesCombo->Clear();
	vesiclesCombo->SetWindowText("");
	cytoskeletonsCombo->Clear();
	cytoskeletonsCombo->SetWindowText("");
	channelsCombo->Clear();
	channelsCombo->SetWindowText("");

	phosphatasesCombo->SetCurSel(0);
	phosphatasesCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioVesicle()
{
	CComboBox* kinasesCombo;
	CComboBox* TFsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonsCombo;
	CComboBox* channelsCombo;


	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	TFsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);

	kinasesCombo->Clear();
	kinasesCombo->SetWindowText("");
	phosphatasesCombo->Clear();
	phosphatasesCombo->SetWindowText("");
	TFsCombo->Clear();
	TFsCombo->SetWindowText("");
	cytoskeletonsCombo->Clear();
	cytoskeletonsCombo->SetWindowText("");
	channelsCombo->Clear();
	channelsCombo->SetWindowText("");

	vesiclesCombo->SetCurSel(0);
	vesiclesCombo->SetFocus();
}

void CDialogPathwayGenerator::OnBnClickedRadioCytoskeleton()
{
	CComboBox* kinasesCombo;
	CComboBox* TFsCombo;
	CComboBox* phosphatasesCombo;
	CComboBox* vesiclesCombo;
	CComboBox* cytoskeletonsCombo;
	CComboBox* channelsCombo;


	kinasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_KINASE);
	TFsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TF);
	phosphatasesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_PHOSPHATASE);
	vesiclesCombo = (CComboBox*) GetDlgItem(IDC_COMBO_VESICLE);
	cytoskeletonsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CYTOSKELETON);
	channelsCombo = (CComboBox*) GetDlgItem(IDC_COMBO_CHANNEL);

	kinasesCombo->Clear();
	kinasesCombo->SetWindowText("");
	phosphatasesCombo->Clear();
	phosphatasesCombo->SetWindowText("");
	vesiclesCombo->Clear();
	vesiclesCombo->SetWindowText("");
	TFsCombo->Clear();
	TFsCombo->SetWindowText("");
	channelsCombo->Clear();
	channelsCombo->SetWindowText("");

	cytoskeletonsCombo->SetCurSel(0);
	cytoskeletonsCombo->SetFocus();
}

void CDialogPathwayGenerator::OnCbnSelchangeComboChannel()
{
	// TODO: Add your control notification handler code here
}


